<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admin
 *
 * @author QUYET
 */
class Admin extends Admin_Controller {
    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('news/news_m');
        $this->session->set_userdata('current_url', current_url());
    }
    function index(){
        $about_info = $this->news_m->get_aboutus();
        if(!empty($_POST) && !empty($_POST['title']) && !empty($_POST['description']) && !empty($_POST['meta_title']) && !empty($_POST['meta_description']) && !empty($_POST['meta_keyword']))
        {
            if(empty($about_info)){
                $this->news_m->add_news(array('title'=>$_POST['title'],
                                         'description'=>$_POST['description'],
                                         'meta_title'=>$_POST['meta_title'],
                                         'meta_description'=>$_POST['meta_description'],
                                         'meta_keyword'=>$_POST['meta_keyword']
                                        ));
                redirect('admin/about-us');
            }
            else{
                $this->news_m->update_news(array('title'=>$_POST['title'],
                                         'description'=>$_POST['description'],
                                         'meta_title'=>$_POST['meta_title'],
                                         'meta_description'=>$_POST['meta_description'],
                                         'meta_keyword'=>$_POST['meta_keyword']
                                        ),($this->session->userdata('lang')=='en'?2:1));
            }
        }
        else{
            if(!empty($about_info)){
                $_POST['title'] = $about_info->title;
                $_POST['description'] = $about_info->description;
                $_POST['meta_title'] = $about_info->meta_title;
                $_POST['meta_description'] = $about_info->meta_description;
                $_POST['meta_keyword'] = $about_info->meta_keyword;
            }
        }        
        
        $this->display_admin('admin/about_us',array('aboutus'=>$about_info));
    }
}

?>
